<?php
include_once(ROOTDIR.'include/validatecode.class.php');
include_once(ROOTDIR.'include/amap.class.php');
class Member_con extends Lxbase {

	public $projectId = '1481169291265';

	/**
	 * 登录
	 */
	public function login(){
		if(isset($_SESSION['userinfo']) && $_SESSION['userinfo']){
			header('location:?g=index&m=index&a=index');exit;
		}
		$this->smarty->display("login_index.tpl");
	}

	/**
	 * 验证码
	 */
	public function vc(){
		$_vc = new ValidateCode;
		$_vc->doimg();
		$_SESSION['vc'] = $_vc->getCode();exit;
	}

	/**
	 * 我要营销
	 */
	public function marketing(){
		$this->smarty->display("marketing.tpl");
	}

	/**
	 * 登录验证
	 */
	public function checkLogin(){
		if(strtolower($_POST['validate'])!=$_SESSION['vc']){
			die("<script>parent.showerror('checkvc');</script>");
		}
		$username = trim($_POST['username']);
		$endtime = $this->viewdata('id,end_time,hytype,status','users','where username = "' . $username . '"');
		if(empty($endtime)){
			die("<script>parent.showerror('erroruser');</script>");
		}
		if(!empty($endtime['end_time'])){
			if((int)$endtime['end_time']<time()){
				die("<script>parent.showerror('timeend');</script>");
			}
		}
        if(!$endtime['status']){
            die("<script>parent.showerror('jinyong');</script>");
        }
		$password = trim($_POST['password']);
		if(!$username || !$password){
			echo '帐号或密码不能为空！';exit;
		}
		$hytypes = explode(',',$endtime['hytype']);
		if(!empty($endtime['id']) && in_array('6',$hytypes)){
			$shoparr = array(
					'app' => 'asynlogin',
					'act' => 'yunmall',
					'user_name' => $username,
					'password' => $password
			);
			if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/'){
				$sendurl = 'http://weidian.zhongsou.com/index.php';
			}else{
				$sendurl = 'http://weidian1.zhongsou.com/index.php';
			}
			$result = json_decode($this->call_post($sendurl,$shoparr),true);
			if( $result && $result['head'] == 200){
				if( isset($result['shopinfo']) && is_array($result['shopinfo']) ){
					foreach ( $result['shopinfo'] as $key=>$val ){
						setcookie($key,$val,0,"/",".zhongsou.com");
					}
				}
			}
		}
		$redirectUrl = urlencode($this->basehost.'?g=user&m=member&a=getLoginRes');
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/'){
			$sendurl = 'http://user.zhongsou.com/usercenter/normal/user/signin?username=' . $username . '&password=' . $password . '&redirectUrl=' . $redirectUrl . '&projectId=' . $this->projectId;
		}else{
			$sendurl = 'http://usertest.zhongsou.com/usercenter/normal/user/signin?username=' . $username . '&password=' . $password . '&redirectUrl=' . $redirectUrl . '&projectId=' . $this->projectId;
		}
		header('Location: ' . $sendurl);exit;
	}

	/**
	 * 获取登录结果
	 */
	Public function getLoginRes(){
		$code = $_GET['code'];
		if($code=='200'){
			$uid = $_COOKIE['UID'];
			//根据UID调接口，获取配置信息
			$_SESSION['userinfo']['uid'] = $uid;
			$res = $this->viewdata('*','users',"where uid='{$uid}'");
			$_SESSION['userinfo']['userid'] = $res['id'];
			$res['hytype'] = explode(',',$res['hytype']);
			if(in_array('3',$res['hytype'])){
				//行业酒店版
				$hyid = $this->viewdata('id','hotel',"where uid=".$res['id']);
				if($hyid){
					$_SESSION['hyid'] = $hyid['id'];
				}else{
					$_SESSION['hyid'] = 0;
				}
			}
			$_SESSION['userinfo']['gid'] = $res['hytype'];
			$_SESSION['userinfo']['token'] = $res['token'];
			$_SESSION['userinfo']['end_time'] = $res['end_time'];
			$_SESSION['userinfo']['plas'] = explode(',',$res['plas']);
			$_SESSION['userinfo']['uname'] = $_GET['username'];
			die("<script>top.location='?g=index&m=index&a=index';</script>");
		}else{
			die("<script>parent.showerror('showerrorstr','".$_GET["msg"]."');</script>");
		}
	}

	/**
	 * 让企悦登录
	 */
	public function loginToQiyue(){
		if(empty($_SESSION['userinfo'])){
			echo "<script>top.location.href='?g=user&m=member&a=login'</script>";
			exit;
		}
		$modules = Lxbase::getconfig('module');
		//获取功能模块链接参数
		$mid = $_GET['mid'];
		if(!empty($_SESSION["userinfo"]["uid"])){
			$res = $this->mongo()->findOne('history', array("uid"=>$_SESSION['userinfo']['uid']));
			if(!$res){
				$this->mongo()->insert('history',array("uid"=>$_SESSION['userinfo']['uid'],"mid"=>$mid));
			}else{
				$hres = $this->mongo()->findOne('history', array("uid"=>$_SESSION['userinfo']['uid']));
				$hres['mid'] = $mid . ',' . $hres['mid'];
				$temparr = explode(',',$hres['mid']);
				$temparr = array_unique($temparr);
				if(count($temparr)==10){
					array_pop($temparr);
				}
				$hres['mid'] = implode(',',$temparr);
				$this->mongo()->update("history", array("uid"=>$_SESSION['userinfo']['uid']),array('uid'=>$_SESSION['userinfo']['uid'],'mid'=>$hres['mid']));
			}
		}
		$userid=empty($_GET["u"])?$_SESSION["userinfo"]["userid"]:intval($_GET["u"]);
		$userinfo = $this->viewdata("*","users","where id={$userid}");
		$marr = $modules[$mid];
		$pla=$_GET["pla"];
		$marr["pla"]=$pla;
		$mlink = json_encode($marr);
		$sess = array(
			//从session里取用户名
				'uname' => empty($userinfo["username"])?$userinfo['uname']:$userinfo["username"],
				'token' => $userinfo["token"],
				'mlink'	=> $mlink
		);
		$sess = base64_encode(json_encode($sess));
		$urlhost = empty($_SERVER["SERVER_NAME"])?$_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"];
		if($urlhost == 'zq.zhongsou.com' || $urlhost=='kaifa.zq.zhongsou.com'){
			$oldurlhost = 'http://kaifa.vq.zhongsou.com/';
		}else{
			$oldurlhost = 'http://vq.zhongsou.com/';
		}
		$loginUrl = $oldurlhost."index.php?g=Other&m=Connector&a=loginToQiyue&sess=".$sess;
		header('Location: ' . $loginUrl);exit;
	}

	/**
	 * 保存用户信息
	 * kongxf
	 */
	public function saveUserInfo(){
		$data = array();
		$data['projectId'] = $this->projectId;
		//  获取uid、配置信息，调接口，参照addUser方法
	}

	/**
	 * 校验用户名是否可用
	 */
	public function checkUsername($username=''){
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
			$url = 'http://user.zhongsou.com/usercenter/normal/user/username/check?username=' . $username . '&projectId=' . $this->projectId;
		}else{
			$url = 'http://usertest.zhongsou.com:8001/usercenter/normal/user/username/check?username=' . $username . '&projectId=' . $this->projectId;
		}
		return file_get_contents($url);
	}

	/**
	 * 增加用户
	 */
	public function add(){
		$uid = $_COOKIE['UID'];
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
			$sendurl = "http://super.zhongsou.com/super/open/user/role/list?uid=" . $uid;
			$role_id = 1;
		}else{
			$sendurl = "http://supertest.zhongsou.com/super/open/user/role/list?uid=" . $uid;
			$role_id = 8;
		}
		$res = file_get_contents($sendurl);
		$res = json_decode($res,true);
		if($res['code']==200){
			$flag = 0;
			foreach($res['roles'] as $m=>$n){
				if($n['role_id']==$role_id){
					$flag = 1;
				}
			}
			if(!$flag){
				echo '没有添加用户的权限';exit;
			}
			//$groups = $this->arrdata('*','user_group');
			$groups = $this->getconfig('power')['version'];
			$plas = $this->getconfig('power')['pla'];
			$this->smarty->assign('groups',$groups);
			$this->smarty->assign('plas',$plas);
			$this->smarty->display('adduser.tpl');
		}else{
			echo '没有添加用户的权限';exit;
		}
	}

	public function saveedituser(){
		$appname=$_POST["appname"];
        $clientname = $_POST['clientname'];
		if(!empty($_POST["hytp"])){
			$hytp = implode(",",$_POST["hytp"]);
		}
		if(!empty($_POST["plas"])){
			$plas = implode(",",$_POST["plas"]);
		}
		$three_domain = $_POST["three_domain"];
        $domainres = $this->viewdata('username,three_domain','users','where three_domain="' . $three_domain . '"');
        if(!empty($domainres['three_domain']) && $_POST['username'] != $domainres['username']){
            echo '三级域名已存在，请换一个';exit;
        }
		$userid=intval($_POST["userid"]);
		$end_time = strtotime($_POST["end_time"]);
		$into = "appname='{$appname}',clientname='{$clientname}',hytype='{$hytp}',plas='{$plas}',three_domain='{$three_domain}',end_time='{$end_time}'";
		$this->updata("users",$into,"where id={$userid}");
        $updatauid = $this->viewdata('uid,token','users','where id = ' . $userid);
        //设置配置信息
        $ext = array(
            //版本id
            'hytype' => $hytp,
            'token' => $updatauid['token'],
            'plas' => $plas
        );
        $data = array(
            'uid' => $updatauid['uid'],
            'projectId' => $this->projectId,
            'ext' => json_encode($ext)
        );
        if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
            $this->call_post('http://super.zhongsou.com/super/user/config/saveOrUpdate', $data);
        }else{
            $this->call_post('http://supertest.zhongsou.com:8001/super/user/config/saveOrUpdate', $data);
        }
		header("location:?g=user&m=member&a=getuserlist");
		exit;
	}

	/**
	 * 编辑用户
	 */
	public function edituser(){
		$id = (int)$_GET['id'];
		$res = $this->viewdata('*','users','where id = ' . $id);
		$this->smarty->assign('res',$res);
		$this->smarty->assign('setgroups',explode(',',$res['hytype']));
		$this->smarty->assign('setplas',explode(',',$res['plas']));
		$groups = $this->getconfig('power')['version'];
		$plas = $this->getconfig('power')['pla'];
		$this->smarty->assign('groups',$groups);
		$this->smarty->assign('plas',$plas);
		$this->smarty->display('edituser.tpl');
	}


	/**
	 * 保存增加用户
	 */
	public function addUser(){
		$username = trim($_POST['username']);
		$che = $this->viewdata('*','users','where username = "' . $username . '"');
		if($che){
			echo '注册失败，用户名已经存在';exit;
		}
        $three_domain = $_POST['three_domain'];
        $domainres = $this->viewdata('id','users','where three_domain="' . $three_domain . '"');
        if(!empty($domainres)){
            echo '三级域名已存在，请换一个';exit;
        }
		$plas = '';
        if(!empty($_POST['plas'])){
            foreach($_POST['plas'] as $n){
                $plas .= $n . ',';
            }
        }
		$plas = rtrim($plas,',');
		//检测用户名是否为搜悦号
		$cres = $this->checkUsername($username);
		$cres = json_decode($cres,true);
		if(isset($cres['valid']) && !$cres['valid']){
		$password = $_POST['password'];
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
			$url = 'http://user.zhongsou.com/usercenter/normal/user/2b/signup?username=' . $username . '&password=' . $password;
		}else{
			$url = 'http://usertest.zhongsou.com/usercenter/normal/user/2b/signup?username=' . $username . '&password=' . $password;
		}
		$rres = file_get_contents($url);
		$rres = json_decode($rres,true);
		if(isset($rres['code']) && $rres['code']==200){
			//插入企悦用户表
			$qydata = array();
			$qydata['username'] = $username;
			$qydata['uid'] = $rres['uid'];
			//生成token
			$randLength=6;
			$chars='abcdefghijklmnopqrstuvwxyz';
			$len=strlen($chars);
			$randStr='';
			for ($i=0;$i<$randLength;$i++){
				$randStr.=$chars[rand(0,$len-1)];
			}
			$tokenvalue=$randStr.time().rand(1000,9999);
			$qydata['token'] = $tokenvalue;
			$qydata['plas'] = $plas;
			$qydata['three_domain'] = $_POST['three_domain'];
			$qydata['clientname'] = $_POST['clientname'];
			$qydata['appname'] = $_POST['appname'];
			$qydata['start_time'] = time();
			$qydata['p_uid'] = $_COOKIE['UID'];
			$qydata['end_time'] = strtotime($_POST['end_time']);
			if(!empty($_POST["hytype"])){
				$qydata['hytype'] = implode(",",$_POST["hytype"]);
			}
			$userid = $this->setdata('users',$qydata);
			//设置配置信息
			$ext = array(
				//版本id
					'hytype' => $qydata["hytype"],
					'token' => $tokenvalue,
					'plas' => $plas
			);
			$data = array(
					'uid' => $rres['uid'],
					'projectId' => $this->projectId,
					'ext' => json_encode($ext)
			);
			if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
				$res = $this->call_post('http://super.zhongsou.com/super/user/config/saveOrUpdate', $data);
			}else{
				$res = $this->call_post('http://supertest.zhongsou.com:8001/super/user/config/saveOrUpdate', $data);
			}
			$res = json_decode($res,true);
			if($res['code']==200){
				echo '开通成功';exit;
			}else{
				echo '注册失败,' . $res['msg'];exit;
			}
		}else{
			echo '注册失败,' . $rres['msg'];exit;
		}
		}else{
			echo '注册失败,搜悦号不存在';exit;
		}
	}

	/**
	 * 根据UID获取用户配置信息
	 */
	public function getUserInfo($uid=''){
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/'){
			return file_get_contents('http://super.zhongsou.com/super/user/config/get?uid=' . $uid . '&projectId=' . $this->projectId);
		}else{
			return file_get_contents('http://supertest.zhongsou.com:8001/super/user/config/get?uid=' . $uid . '&projectId=' . $this->projectId);
		}
	}

	/**
	 * 根据UID获取用户配置信息（测试用）
	 */
	public function getUserInfo2($uid=''){
		$uid = '8ccd16a6350106daca6793d2c56118b1be3aa276';
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/'){
			$res = file_get_contents('http://super.zhongsou.com/super/user/config/get?uid=' . $uid . '&projectId=' . $this->projectId);
		}else{
			$res = file_get_contents('http://supertest.zhongsou.com:8001/super/user/config/get?uid=' . $uid . '&projectId=' . $this->projectId);
		}
		var_dump(json_decode($res,true));exit;
	}

	/**
	 * 添加版本
	 */
	public function addGroup(){
		if($_POST){
			$gname = trim($_POST['gname']);
			$res = $this->setdata('user_group',"name = '{$gname}'");
			if($res){
				header('location:?g=user&m=member&a=addGroup');
			}else{
				echo '添加失败';exit;
			}
		}else{
			$this->smarty->display("addgroup.tpl");
		}
	}

	/**
	 * 退出登录
	 */
	public function logout() {
		session_destroy();
		unset($_SESSION);
		session_unset();
		$_SESSION = array();
        setcookie('UID','',-1);
		header('location:?g=user&m=member&a=login');exit;
	}

	/**
	 * 测试用户
	 */
	public function test(){
		$_SESSION['userinfo']['uid'] = 'ded0e6b2560c4370fbde8ac8b97a8d5ce2821e67';
		$_SESSION['userinfo']['userid'] = '1';
		$_SESSION['userinfo']['gid'] = array('3','4','5','6','7','8','9','10','11','12','13','14','15');
		$_SESSION['userinfo']['token'] = 'testtoken';
		$_SESSION['userinfo']['plas'] = '4,9,13,15,16,17,18';
		$_SESSION['hyid'] = 1;
		$_SESSION['userinfo']['uname'] = 'kxf001';
		header('location:?g=index&m=index&a=index');exit;
	}

	/**
	 * 商户设置
	 */
	public function company(){
		$this->smarty->assign('uid',$_SESSION['userinfo']['userid']);
		if($_POST){
			$data = array();
			$data['userid'] = $_SESSION['userinfo']['userid'];
			$data['name'] = $_POST['name'];
			$data['cname'] = $_POST['cname'];
			$data['cateid'] = $_POST['cateid'];
			$data['tel'] = $_POST['tel'];
			$data['phone'] = $_POST['phone'];
			$data['province'] = $_POST['province'];
			$data['city'] = $_POST['city'];
			$data['district'] = $_POST['district'];
			$data['address'] = $_POST['address'];
			$data['logourl'] = $_POST['logourl'];
			$data['latitude'] = $_POST['latitude'];
			$data['longitude'] = $_POST['longitude'];
			$data['intro'] = $_POST['intro'];
			$vqdbarr = Lxbase::getconfig("olddb");
			$vqconn = new Lxdb($vqdbarr);
			if($_POST['cid']){
				//编辑
				$res = $this->updata('company',$data,' where id='.$_POST['cid']);
				unset($data['userid']);
				unset($data['cname']);
				$data['cate_id'] = $data['cateid'];
				$data['mp'] = $data['phone'];
				unset($data['phone']);
				unset($data['cateid']);
				$data['username'] = $_SESSION['userinfo']['uname'];
				$data['password'] = '';
				$vqres = $vqconn->viewdata('*','company','where token = "' . $_SESSION['userinfo']['token'] . '"');
				if(!empty($vqres)){
					$vqconn->updata('company',$data,'where token = "' . $_SESSION['userinfo']['token'] . '"');
				}else{
					$data['amapid'] = 0;
					$data['display'] = 1;
					$data['token'] = $_SESSION['userinfo']['token'];
					$data['location_id'] = 0;
					$data['cat_name'] = '';
					$data['password'] = '';
					$vqconn->setdata('company',$data);
				}
			}else{
				//添加
				$res = $this->setdata('company',$data);
				$data['amapid'] = 0;
				$data['display'] = 1;
				$data['mp'] = $data['phone'];
				unset($data['phone']);
				$data['cate_id'] = $data['cateid'];
				unset($data['cateid']);
				$data['token'] = $_SESSION['userinfo']['token'];
				$data['location_id'] = 0;
				$data['cat_name'] = '';
				$data['password'] = '';
				$data['username'] = $_SESSION['userinfo']['uname'];
				unset($data['userid']);
				unset($data['cname']);
				$vqconn->setdata('company',$data);
			}
			if($res){
				echo "<script>alert('操作成功');parent.location.href='?g=user&m=member&a=company&'+Math.random();</script>";exit;
			}
		}
		$res = $this->viewdata('*','company','where userid='.$_SESSION['userinfo']['userid']);
		if($res){
			$this->smarty->assign('info',$res);
		}else{
			$this->smarty->assign('info',array());
		}
		$wxinfo = $this->viewdata("*","wxuser","where userid={$this->userinfo['userid']}");
		$apinfo = $this->viewdata("*","apuser","where userid={$this->userinfo['userid']}");
		$wxseturl = $this->basehost."?g=wx&m=wxapi&u=".$this->userinfo['userid'];
		$this->smarty->assign("wxinfo",$wxinfo);
		$this->smarty->assign("apinfo",$apinfo);
		$this->smarty->assign("basehost",$this->basehost);
		$this->smarty->assign("wxseturl",$wxseturl);
		if(!empty($_GET["selnum"])){
			$this->smarty->assign("selnum",$_GET["selnum"]);
		}
		$urlhost = empty($_SERVER["SERVER_NAME"])?$_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"];
		if($urlhost == 'zq.zhongsou.com' || $urlhost=='kaifa.zq.zhongsou.com'){
			$this->smarty->assign("debug",1);
		}
		$this->smarty->display("merchants_set_up.tpl");
	}

	/**
	 * 百度地图
	 */
	public function setLatLng_amap(){
		$amap=new amap();
		$this->smarty->assign('key',$amap->key);
		$this->smarty->display('setlatlng_amap.tpl');
	}

	/**
	 * ajax 图片上传
	 */
	public function uploadimg(){
		if($_FILES['uploadimg']['error']){
			echo json_encode(array('status'=>0,'msg'=>'上传失败'));exit;
		}
		$uptypes = array(
				'image/jpg',
				'image/jpeg',
				'image/png',
				'image/pjpeg',
				'image/gif',
				'image/bmp',
				'image/x-png'
		);
		if(!in_array($_FILES['uploadimg']['type'],$uptypes)){
			echo json_encode(array('status'=>0,'msg'=>'上传失败,文件类型不正确'));exit;
		}
		if($_FILES['uploadimg']['size']>2097152){
			echo json_encode(array('status'=>0,'msg'=>'上传失败,文件大小不能超过2M'));exit;
		}
		$res = $this->upload($_FILES['uploadimg'],'user');
		echo json_encode(array('status'=>1,'msg'=>$res['pic']));exit;
	}

	/**
	 * 左侧 — 我要营销
	 */
	public function myMarke(){
		$urlhost = empty($_SERVER["SERVER_NAME"])?$_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"];
		if($urlhost == 'zq.zhongsou.com' || $urlhost=='kaifa.zq.zhongsou.com'){
			$this->smarty->assign("debug",1);
		}
		$this->smarty->assign("userid",$this->userinfo["userid"]);
		$this->smarty->assign("fromtoken",md5('qy_!@#$%^'));
		$this->smarty->display("my_marketing.tpl");
	}

	/**
	 * 左侧 — 我要推广
	 */
	public function myPromote(){
		$urlhost = empty($_SERVER["SERVER_NAME"])?$_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"];
		if($urlhost == 'zq.zhongsou.com' || $urlhost=='kaifa.zq.zhongsou.com'){
			$this->smarty->assign("debug",1);
		}
		$this->smarty->display("my_promote.tpl");
	}

	/**
	 * 修改密码
	 */
	public function modifyPwd(){
		$username = $_SESSION['userinfo']['uname'];
		$oldpass = $_POST['oldpass'];
		$password = $_POST['password'];
		if($this->basehost=='http://qiyuenew.zhongsou.com/' || $this->basehost=='http://qiyue.zhongsou.com/') {
			$sendurl = 'http://user.zhongsou.com/usercenter/cors/user/pwd/modify?username=' . $username . '&newPassword=' . $password . '&password=' . $oldpass;
		}else{
			$sendurl = 'http://usertest.zhongsou.com:8001/usercenter/cors/user/pwd/modify?username=' . $username . '&newPassword=' . $password . '&password=' . $oldpass;
		}
		$res = file_get_contents($sendurl);
		$res = json_decode($res,true);
		if($res['code']=='200'){
			echo "<script>alert('修改成功');</script>";exit;
		}else{
			echo "<script>alert('修改失败');</script>";exit;
		}
	}

	/**
	 * 根据渠道UID获取客户列表
	 */
	public function getUserList(){
		$uid = $_COOKIE['UID'];
		$where = "where status=1 and p_uid = '" . $uid . "'";
		$oldpar = array();
		if(!empty($_POST['username'])){
			$where .= " and locate('".$_POST['username']."',username)";
			$oldpar['username'] = $_POST['username'];
		}
		if(!empty($_POST['clientname'])){
			$where .= " and locate('".$_POST['clientname']."',clientname)";
			$oldpar['clientname'] = $_POST['clientname'];
		}
		if(!empty($_POST['appname'])){
			$where .= " and locate('".$_POST['appname']."',appname)";
			$oldpar['appname'] = $_POST['appname'];
		}
		if(!empty($_POST['stime'])){
			$where .= " and end_time >= " . strtotime($_POST['stime']);
			$oldpar['stime'] = $_POST['stime'];
		}
		if(!empty($_POST['etime'])){
			$where .= " and end_time <= " . strtotime($_POST['etime']);
			$oldpar['etime'] = $_POST['etime'];
		}
		if(!empty($_POST['hytype'])){
			$where .= " and find_in_set(" . $_POST['hytype'] . ",hytype)";
			$oldpar['hytype'] = $_POST['hytype'];
		}
        $where .= ' order by id desc';
		$res = $this->arrdata('*','users',$where);
		$groups = $this->getconfig('power')['version'];
		foreach($res as $k=>$v){
			$tempstr = '';
			$temp = explode(',',$v['hytype']);
			foreach($temp as $m=>$n){
				$tempstr .= $groups[$n] . ',';
			}
			$res[$k]['gname'] = rtrim($tempstr,',');
		}
		$this->smarty->assign('groups',$this->getconfig('power')['version']);
		$this->smarty->assign('lists',$res);
		$this->smarty->assign('oldpar',$oldpar);
		$this->smarty->display('userlists.tpl');
	}

	/**
	 * 修改UID
	 */
	public function edituid(){
		$uid = 'e51e41f7df321a894496692721599eb9fe1c13a7';
		$this->updata('users','uid = "' . $uid . '"','where id = 12');
		echo OK;exit;
	}

	//给老企悦返回微信信息 表 qy_wxuser
	public function  getwxinfo(){

		$condition = $_REQUEST['condition'];
		if(empty($condition)){
			return false;
		}else{
			$condition=json_decode($condition,true);
			$vqdbarr = Lxbase::getconfig("db");
			$vqconn = new Lxdb( );
			$useid = $vqconn->viewdata("id","{$condition['table']}", 'where token = "' . $condition['token'] . '"');

			if(!empty($useid["id"])){
				$wxinfo= $vqconn->viewdata("*","wxuser",'where userid="'.$useid['id'].'"');
				//var_dump($wxinfo);
				return $wxinfo ;
			}
		}
	}

    // 禁用、启用帐号
    public function setStatus(){
        $uid = $_POST['uid'];
        $type = $_POST['type'];
        $res = $this->updata("users",'status='.$type,'where id='.$uid);
        if($res){
            echo json_encode(array('status'=>1));exit;
        }else{
            echo json_encode(array('status'=>0));exit;
        }
    }

}
	
	


